home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / calloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-22  |  1.4 KB  |  54 lines

  1. /* 
  2.  * calloc.c --
  3.  *
  4.  *    Source code for the "calloc" library procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/calloc.c,v 1.2 88/07/29 17:04:26 ouster Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20. #include <bstring.h>
  21. #include "stdlib.h"
  22.  
  23. /*
  24.  *----------------------------------------------------------------------
  25.  *
  26.  * calloc --
  27.  *
  28.  *    Allocate a zero-filled block of storage.
  29.  *
  30.  * Results:
  31.  *    The return value is a pointer to numElems*elemSize bytes of
  32.  *    dynamically-allocated memory, all of which have been
  33.  *    initialized to zero.
  34.  *
  35.  * Side effects:
  36.  *    None.
  37.  *
  38.  *----------------------------------------------------------------------
  39.  */
  40.  
  41. char *
  42. calloc(numElems, elemSize)
  43.     unsigned int numElems;    /* Number of elements to allocate. */
  44.     unsigned int elemSize;    /* Size of each element. */
  45. {
  46.     unsigned int totalSize;
  47.     char *result;
  48.  
  49.     totalSize = numElems*elemSize;
  50.     result = malloc(totalSize);
  51.     bzero(result, (int) totalSize);
  52.     return (char *) result;
  53. }
  54.